package com.urbanski.clipboard.client.util;

import com.urbanski.clipboard.client.action.AdministerActionHandler;
import com.urbanski.clipboard.client.action.ClientActionHandler;
import com.urbanski.clipboard.client.action.ConnectActionHandler;
import com.urbanski.clipboard.client.action.CreateActionHandler;
import com.urbanski.clipboard.client.action.DisconnectActionHandler;
import com.urbanski.clipboard.client.action.ExitActionHandler;
import com.urbanski.clipboard.client.action.HelpActionHandler;
import com.urbanski.clipboard.client.action.InfoActionHandler;
import com.urbanski.clipboard.client.action.JoinActionHandler;
import com.urbanski.clipboard.client.action.LeaveActionHandler;
import com.urbanski.clipboard.client.action.PauseActionHandler;
import com.urbanski.clipboard.client.action.SetAliasActionHandler;
import com.urbanski.clipboard.client.action.TestActionHandler;
import com.urbanski.clipboard.client.action.UnpauseActionHandler;
import com.urbanski.clipboard.common.exception.InvalidCommandException;

public class ClientConstants
{
	private ClientConstants()
	{
	}

	public static enum ClientCommand
	{
		EXIT("exit", ExitActionHandler.class), JOIN("join", JoinActionHandler.class), LEAVE("leave", LeaveActionHandler.class), ADMINISTER("admin", AdministerActionHandler.class), PAUSE("pause", PauseActionHandler.class), UNPAUSE("unpause", UnpauseActionHandler.class), CREATE("create", CreateActionHandler.class), HELP("help", HelpActionHandler.class), CONNECT("connect", ConnectActionHandler.class), DISCONNECT("disconnect", DisconnectActionHandler.class), SET_ALIAS("setalias", SetAliasActionHandler.class), TEST("test", TestActionHandler.class), INFO("info", InfoActionHandler.class);

		private String keyword;
		private Class<? extends ClientActionHandler> actionHandler;

		private ClientCommand(String keyword, Class<? extends ClientActionHandler> actionHandler)
		{
			this.keyword = keyword;
			this.actionHandler = actionHandler;
		}

		public String getKeyword()
		{
			return keyword;
		}

		public Class<? extends ClientActionHandler> getActionHandler()
		{
			return actionHandler;
		}

		public String toString()
		{
			return keyword;
		}

		public static ClientCommand getClientCommand(String keyword) throws InvalidCommandException
		{
			for (ClientCommand command : ClientCommand.values())
			{
				if (command.keyword.equals(keyword))
				{
					return command;
				}
			}

			throw new InvalidCommandException("Invalid command entered: " + keyword);
		}
	}
}
